home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: news.sprintlink.net!mv!bnb
- From: bnb@curtech.com (Brian Ballard)
- Subject: Creating operator= for *pointers* to objects??
- Message-ID: <Do4KtH.MK@mv.mv.com>
- Organization: Current Technology
- Date: Mon, 11 Mar 1996 22:51:17 GMT
- X-Newsreader: TIN [version 1.2 PL2]
- X-Nntp-Posting-Host: artichoke.curtech.com
-
-
-
- I'm trying to find a way to create an assignment (or copy) operator
- which I can use to apply to pointers to object. For example, say I have
- a class hierarchy that looks like:
-
- |--- B
- A ---|--- C
- |--- D
-
- Millions of these objects can potentially be created and scrapped every
- few minutes so, in order to improve performance and reduce memory
- fragmentation, every class in the hierarchy has their new/delete operators
- overloaded to use a handful of "pre-built" objects in the freestore.
- Pretty standard stuff.
-
- Because exact duplicates of an instantiated object can (and must) exist,
- class A has a refCount member which allows me to keep track of how many
- copies of a duplicated object exist out there, so I don't pull the rug
- out from under an object that is still being used.
-
- In general, megabytes worth of network packets are stored in a file, which
- get read in by this software and are wrapped up in one of the above derived
- classes (B, C, or D) depending upon the type of packet. This creates a
- virtual "list" of sorts where I have an iterator which walks through the
- file, returning objects of type B/C/D.
-
- Basically, I'd like to be able to do this:
-
- {
- A* start = NULL;
- A* temp = NULL;
-
- start = mStream->GetPacketAtOffset(0L); // This might return an object B*
- temp = start; // I need this to call my oper=
- while ( temp = mStream->GetNextPacket(temp)) // GetNextPacket automatically
- bla bla bla // 'delete's first A* temp
-
- ...
- }
-
- In the above example, I need "temp = start" to "delete temp", create a
- duplicate of "start" and return its pointer into "temp"
-
- Right now, I have to do this:
-
- {
- ...
- delete temp;
- temp = start->Copy();
- ...
- }
-
- Not a big deal to it this way, but it's easy to forget over the long haul
- that these steps need to be taken. It's much easier to do a simple pointer
- assignment which guarantees that every pointer to an object is accounted for.
-
-
- OK.... a bit much content for such an easy question....
-
- thanx,
- brian
-
-
-
-
-
-
-
- --
- Brian Ballard |
- Current Technology, Inc. | "the ultimate development
- Durham, New Hamsphire | of total harmony....."
- bnb@curtech.com |
-